package leetcode;

import java.util.LinkedList;
import java.util.Queue;

public class MyStack {
      private Queue<Integer> queue1=new LinkedList<>();
      private Queue<Integer> queue2=new LinkedList<>();
      public MyStack(){
      }
      public void push(int x){
              queue1.offer(x);
              while(!queue1.isEmpty()){
                      queue2.offer(queue1.poll());
              }
              Queue<Integer> tmp=queue1;
              queue1=queue2;
              queue2=tmp;
      }
      public int pop(){
              //将首元素取出来
              return queue1.poll();
      }
      public int top(){
              //只是输出并不拿出来
              return queue1.peek();
      }
      public boolean empty(){
              return queue1.isEmpty();
      }

}
